<?php
class	matiere_premiere
{
	private $RefMatiere;
	private $nom;
	private $MatiereArr = array ('RefMatiere' => '',
	'ID_AL' => '',
	'ID_AN' => '',
	'NOM_MATIERE_PREMIERE' => '',
	'ColorHexDecimal' => '',
	'RefCategorie' => '',);


	public	function	GetNom()
	{
		return $this->nom;
	}

	public	function	GetRefMatiere()
	{
		return $this->id;
	}

	public	function	SetId($str)
	{
		$this->RefMatiere = $str;
	}
	public	function	SetNom($str)
	{
		$this->nom = $str;
	}

	public function SetMatiereArr($arrArgs = array ())
	{
		foreach ($this -> MatiereArr as $clef => $val)
		{
			if (array_key_exists ($clef, $arrArgs))
			{
				$this -> MatiereArr[$clef] = $arrArgs[$clef];
			}
			else if (!empty ($val))
			{
				$this -> MatiereArr[$clef] = $val;
			}
		}
	}


	public	function	SetMatiereByReferenceId($idM)
	{
		mysql_connect("localhost", "mygesco", "mygesco") or die("Impossible de se connecter : " . mysql_error());

		mysql_select_db("mygesco");
		$req = 'SELECT * FROM `matiere_premiere` WHERE `RefMatiere` = "CO402010" ' . $idM;
		$result = mysql_query($req);


		while ($row = mysql_fetch_array($result))
		{
			$this -> SetMatiereArr($row);
	//	print_r($this -> MatiereArr);
				
		}

	}

	public function __toString ()
	{
		$chaineTemp = '';
		if (isset ($this -> MatiereArr['RefMatiere']))
		{
			foreach ($this -> MatiereArr as $key => $value)
			{
				$chaineTemp .= "$key: $value\n" . '<br />';
			}	
		}
		return $chaineTemp;
	}

}


// on instancie notre objet
$mat = new matiere_premiere ();

$mat->SetMatiereByReferenceId("");
echo $mat;






?>